window.onload = function () {
    //配置
    var config = {
        vx: 4,//点x轴速度,正为右，负为左
        vy: 4,//点y轴速度
        height: 2,//点高宽，其实为正方形，所以不宜太大
        width: 2,
        count: 100,//点个数
        color: "100, 100, 100",//点颜色
        stroke: "50,50,50",//线条颜色
        dist: 6000,//点吸附距离
        e_dist: 20000,//鼠标吸附加速距离
        max_conn: 10//点到点最大连接数
    }
    //调用
    CanvasParticle(config, 'MyDiv');
}

//楼层滚动
function loc() {
    let divs = document.querySelectorAll("main .location div")
    let lis = document.querySelectorAll("main .particulars")
    let timeId = null
    divs.forEach((i, j) => {
        i.addEventListener("click", function () {
            divs.forEach((k) => {
                k.classList.remove("active")
            });
            i.classList.add("active")

            // 判断滚动条是否到达最底部
            window.onscroll = function () {
                var a = document.documentElement.scrollTop == 0 ? document.body.clientHeight :
                    document.documentElement.clientHeight;
                var b = document.documentElement.scrollTop == 0 ? document.body.scrollTop :
                    document.documentElement.scrollTop;
                var c = document.documentElement.scrollTop == 0 ? document.body.scrollHeight :
                    document.documentElement.scrollHeight;
                if (a + b == c && b != 0) {
                    clearInterval(timeId)
                    timeId = null
                }
            }
            if (timeId) {
                return
            }
            if (document.documentElement.scrollTop >= lis[j].offsetTop) {
                timeId = setInterval(() => {
                    document.documentElement.scrollTop -= 40
                    if (document.documentElement.scrollTop <= lis[j].offsetTop) {
                        clearInterval(timeId)
                        timeId = null
                    }
                }, 20);
            } else {
                timeId = setInterval(() => {
                    document.documentElement.scrollTop += 40
                    if (document.documentElement.scrollTop >= lis[j].offsetTop) {
                        clearInterval(timeId)
                        timeId = null
                    }
                }, 20);
            }
        })
    });
}
loc()